package gameos.core;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

public class DataSave 
{
	public boolean sound;
	public boolean vibrate;
	public int scoreMax;
	public int kill;
	public int move;
	public int money;
	public int[] stateMap = new int[8];
	public int[] scoreUnlock = {};
   protected Preferences getPrefs()
   {
       return Gdx.app.getPreferences("KungfuStreet");
   }
   
   public void getAll()
   {
   	sound = getPrefs().getBoolean("sound", true);
   	vibrate = getPrefs().getBoolean("vibrate", true);
   	scoreMax = getPrefs().getInteger("score", 0);
   	kill = getPrefs().getInteger("kill", 0);
   	move = getPrefs().getInteger("move", 0);
   	money = getPrefs().getInteger("money", 10000);
   	for(int i = 0; i< 8;i++)
   	{
   		int df = 0;
   		if(i==1)
   		{
   			df = 1;
   		}
   		stateMap[i] = getPrefs().getInteger("map"+(i+1),df);
   	}
   }
   
   public void saveAll()
   {
   	getPrefs().putBoolean("sound", sound);
   	getPrefs().flush();
   	getPrefs().putBoolean("vibrate", vibrate);
   	getPrefs().flush();
   	getPrefs().putInteger("score", scoreMax);
   	getPrefs().flush();
   	getPrefs().putInteger("kill", kill);
   	getPrefs().flush();
   	getPrefs().putInteger("move", move);
   	getPrefs().flush();
   	getPrefs().putInteger("money", money);
   	getPrefs().flush();
   	for(int i = 0; i< 8;i++)
   	{   
   		getPrefs().putInteger("map"+(i+1),stateMap[i]);
   		getPrefs().flush();
   	}
   	getPrefs().flush();
   }
      
   public void saveScore(int score, int kill, int move)
   {
   	if(score>=scoreMax)
   	{   	
   		this.scoreMax = score;
   		this.kill = kill;
   		this.move = move;
   		saveAll();
   	}
   }
}
